/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package projeto;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Juarez
 */
public class Projeto {

    private int count = 0;

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Projeto projeto = new Projeto();
        System.setProperty("http.proxyHost", "192.168.3.5");
        System.setProperty("http.proxyPort", "3128");
        //Caso tenha usuário e senha   
        System.getProperties().put("proxySet", "true");
        System.setProperty("http.proxyUser", "jfsantos4");
        System.setProperty("http.proxyPassword", "teste");
        String[] keys = new String[]{"1", "2", "3", "4", "5", "6", "7", "8", "9",
            "0", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
            "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a",
            "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o",
            "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
        while (projeto.ehVerdadeiro()) {
            String strTmp = "";
            for (int i = 0; i < 5; i++) {
                strTmp += keys[new Random().nextInt(keys.length - 1)];
            }
            // a string da url
            String urlString = "http://www.google.com.br/#hl=pt-BR&source=hp&q=" + strTmp
                    + "&btnG=Pesquisa+Google&aq=f&aqi=&aql=&oq=atetrafdsdf&bav=on.2,or.r_gc.r_pw.&fp=5d2d91ddc427ca50&biw=1280&bih=347";
            strTmp = "";
            try {
                // cria o objeto url
                URL url = new URL(urlString);
                // cria o objeto httpurlconnection
                HttpURLConnection connection =
                        (HttpURLConnection) url.openConnection();
                // seta o metodo
                connection.setRequestProperty("Request-Method", "GET");
// seta a variavel para ler o resultado
                connection.setDoInput(true);
                connection.setDoOutput(false);
// conecta com a url destino
                connection.connect();
// abre a conexão pra input
                BufferedReader br =
                        new BufferedReader(new InputStreamReader(connection.getInputStream()));
// le ate o final
                StringBuffer newData = new StringBuffer(10000);
                String s = "";
                while (null != ((s = br.readLine()))) {
                    newData.append(s);
                }
                br.close();
// imprime o codigo resultante
                System.out.println(new String(newData));

// imprime o numero do resultado
                System.out.println(
                        "Resultado: "
                        + connection.getResponseCode() + "/" + connection.getResponseMessage());
            } catch (Exception ex) {
                Logger.getLogger(Projeto.class.getName()).log(Level.SEVERE, null, ex);
            }
            PrintWriter out = new PrintWriter(System.out, true);
            System.out.println("Eh verdadeiro!!!");
        }
    }

    private boolean ehVerdadeiro() {
        this.teste(new ArrayList<Object>());
        return true;
    }

    public void teste(List<Object>... obj) {
        obj[0].get(0);
    }
}
